{include file="admin@public/header"/}

<style>
	#matchCon {
		width: 160px;
	}

	.url-box {
		padding: 5px 10px;
		line-height: 26px;
		cursor: pointer;
	}

	.url-box a {
		margin-right: 5px;
	}
</style>


<div class="bill-ser-top">
	<ul class="ul-inline cf">
		<li>
			<input type="text" id="matchCon" class="ui-input ui-input-ph" placeholder="请输入单据号或供应商或备注" style="width: 190px;">
		</li>
		<li>
			<label>日期:</label>
			<input type="date" id="startdate" class="ui-input "  value="{$month.month_start|date='Y-m-d',###}" style="width: 125px;">
			<i>-</i>
			<input type="date" id="enddate" class="ui-input "  value="{$month.month_end|date='Y-m-d',###}" style="width: 125px;">
		</li>
		<li><a class="mrb more ui-btn" id="moreCon" onclick="heightSearch('/admin/basic/hight_search.html?o_type={$o_type}','高级搜索','483px','460px')">高级搜索</a><a class="ui-btn mrb ui-btn-search" id="search">查询</a></li>
		<!-- <li class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5704" target="_blank" class="video-icon"></a>购货订单查询</li> -->
	</ul>
</div>
<div class="wrapper btc">
	<div class="bill-ser-botm cf">
		<div class="ui-config-box">
			<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
		</div>
		<div class="fr">
            <a class="ui-btn-bill ui-btn-add mrb" id="add" tabid="money" data-right="VERIFICA_ADD" tabTxt="核销单" parentOpen="true" rel="pageTab" _href="/money/verifica/add.html">新增</a> 
            <a class="ui-btn-bill ui-btn-hl mrb" id="export">导出</a>
            <a href="#" class="ui-btn-bill ui-btn-hl mrb" id="del">删除</a>
        </div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>


<script type="text/javascript">
	//$(function(){
	$(document).ready(function () {

        // 获取当前日期
        // var myDate = new Date;
        // var year = myDate.getFullYear(); //获取当前年
        // var mon = myDate.getMonth() + 1; //获取当前月
        // var date = myDate.getDate(); //获取当前日
        // console.log(year + '-' + mon + '-' + date)
        // if (mon < 10) {
        // mon = "0" + mon;
        // }
        // if (date < 10) {
        // date = "0" + date;
        // }
        // $("#startdate").val(year + '-' + mon + '-01');
        // $("#enddate").val(year + '-' + mon + '-' + date);

		// 跳转打开新标签页
		$("#add").click(function () {
			var tabid = $(this).attr('tabid');
			var tabTxt = $(this).attr('tabTxt');
			var _href = $(this).attr('_href');
			parent.tab.addTabItem({
				tabid: tabid,
				text: tabTxt,
				url: _href
			})
		})

		// 鼠标移入订单状态
		$("#filter-menu").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		})
		// 按钮移入移出
		$(".ui-btn-menu.ml10").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		})

		//alert("1111");
		$("#grid").jqGrid({
			url: '/money/verifica/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			colNames: [ "ID", "操作","单据日期", "单据编号", "业务类型", "客户名称","供应商名称", '核销金额', "制单人", "备注"],
			colModel: [
                { name: 'id',hidden:true },
				{ name: 'actions', width: 80, formatter: actions,align:'center', lable:"操作"},
				{ name: 'dj_time',width: 100,align:'center', lable:"单据日期"},
				{ name: 'sn',width: 120,align:'center' ,lable:"单据编号"},
				{ name: 'type_name', width: 100,align:'center', lable:"业务类型"},
				{ name: 'customer_name',width: 200,align:'center', lable:"客户名称" },
				{ name: 'supplier_name',width: 200,align:'center', lable:"供应商名称" },
				{ name: 'hexiao_jine',width: 100,align:'center', lable:"核销金额" },
				{ name: 'add_user_name',width: 80,align:'center', lable:"制单人" },
				{ name: 'mark',width: 200,align:'center', lable:"备注" },
			],
			sortable: true,  //排序
		
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
            rownumbers:true,
            multiselect:true,//自带多选
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			//双击表格行事件
            ondblClickRow: function(row){
                var rowData = $('#grid').jqGrid('getRowData',row);
                console.log(rowData.id);
                //var start_date = $('input[name=start_date]').val();
                //var end_date = $('input[name=end_date]').val();
                parent.tab.addTabItem({
                    tabid: "purchaseinvPu",
                    text: "核销单",
                    url:"/money/verifica/details.html?id="+rowData.id,
                })
                   
            }
		});
	});


	//工具栏
	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="lopen(\'edit.html?id=' + rowObject.id + '\',\'编辑\',\'400px\',\'300px\')">修改</span> <span class="ui-icon ui-icon-trash" onclick="order_del(' + rowObject.id + ')">删除</span></div>';
	}

	 //获取表格选中数据
    function selectdata(){
        var rowid=$("#grid").jqGrid("getGridParam","selrow");
        // console.log(rowid);
        var rowData=jQuery("#grid").jqGrid("getRowData",rowid);
        // console.log(rowData);
        var arr = new Array();
        arr['id'] = rowid;
        arr['data'] = rowData;
        return arr;
    }

    // 删除按钮
	$("#del").click(function () {
		var xz = selectdata();
		if(xz['id']==null){
			layer.msg("请选中要删除的数据");
			return false;
		}
        order_del(xz['id']);	
	})
	 // 删除方法
	function order_del($id){
		 layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
            url: '{:url("del")}?id=' + $id,
                beforeSend: function () {
                   load = layer.load(1);
                },
                success: function (data) {
                    if (data.status == 1) {
                        parent.layer.close();
                        layer.msg('已删除!', {time: 1000});
                        window.location.reload();
                        parent.layer.closeAll();
                    } else {
                        layer.msg(data.msg, {time: 1000});
                    }
                }
            }).always(function () {
                layer.close(load);
            });
        });

	}

	// 审核按钮
	$("#shenhe").click(function () {
		var xz = selectdata();
		if(xz['id']==null){
			layer.msg("请先选中要操作的数据");
			return false;
		}
        order_shenhe(xz['id'],1);	
	})

		// 反审核按钮
	$("#reshenhe").click(function () {
		var xz = selectdata();
		if(xz['id']==null){
			layer.msg("请先选中要操作的数据");
			return false;
		}
        order_shenhe(xz['id'],2);	
	})

	 // 审核方法--1,审核 2，反审核
	function order_shenhe($id,$type){

        $.ajax({
        	url: '{:url("shenhe")}?id=' + $id +'&type=' +$type,
            beforeSend: function () {
                load = layer.load(1);
            },
            success: function (data) {
            	if (data.status == 1) {
                	layer.msg(data.msg, {time: 1000});
                    window.location.reload();
                  
                } else {
                    layer.msg(data.msg, {time: 1000});
                }
            }
            
        }).always(function () {
            layer.close(load);
        });
	}


</script>

{include file="admin@public/footer"/}